package EA.testproblems;
import EA.*;

/*
  Branin RCOS function
  
  parameters: 
  a = 1
  b = 5.1/(4*pi^2)
  c = 5/pi
  d = 6
  e = 10
  f = 1/(8*pi)

  Created: 29. sept. 1999
  @version 1.0
  @author Rene Thomsen

 (((y - (5.1/(4*pi*pi))*x*x + (5/pi)*x - 6)**2) + 10*(1-(1/(8*pi)))*cos(x)+10);

*/

public class BraninRCOS extends NumericalProblem 
{

  // Easier way to build max and min
    private double[][] lmax = new double[0][2];
    private double[][] lmin = {{-Math.PI,12.275},{Math.PI,2.275},{9.42478,2.475}};

    public BraninRCOS()
    {
      super();

      double[] optimas;

      name = "Branin RCOS function";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		  return (Math.pow((realpos[1] - (5.1/(4*Math.PI*Math.PI))*realpos[0]*realpos[0] + (5/Math.PI)*realpos[0] - 6),2) + 10*(1-(1/(8*Math.PI)))*Math.cos(realpos[0])+10);
	      };
	  };

      dimensions = 2;
      ismaximization = false;
      optimumradius = 0.2;

      intervals = new Interval[2];
      intervals[0] = new Interval(-5, 10);
      intervals[1] = new Interval(0, 15);
      
      // Set up known maximas
      knownmaxima = new NumericalOptimum[lmax.length];

      for (int i=0;i<lmax.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmax[i][0];
	optimas[1] = lmax[i][1];
	knownmaxima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), true, false, i);
      }

      // Set up known minimas
      knownminima = new NumericalOptimum[lmin.length];

      for (int i=0;i<lmin.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmin[i][0];
	optimas[1] = lmin[i][1];
	knownminima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), false, false, i);
      }
    }
}
